﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Aceso.Domain
{
    /// <summary>
    /// 仓储接口需要约束在聚合根上，以便所有的仓储操作都只能应用在聚合根上
    /// </summary>
    public interface IRepository<TAggregateRoot> where TAggregateRoot : class, IAggregateRoot
    {

        //************编辑**************
        TAggregateRoot Add(TAggregateRoot t);
        TAggregateRoot Update(TAggregateRoot t);
        int Delete(TAggregateRoot t);
        int Delete(Expression<Func<TAggregateRoot, bool>> predicate);

        //************查询**************
        IQueryable<TAggregateRoot> GetAll();
        // 根据聚合根的ID值，从仓储中读取聚合根
        TAggregateRoot GetByKey(Guid key);
        IQueryable<TAggregateRoot> LoadEntities(Expression<Func<TAggregateRoot, bool>> predicate);
        IQueryable<TAggregateRoot> LoadPageEntities(Expression<Func<TAggregateRoot, bool>> predicate, out int totalCount, int pageIndex = 1, int pageSize = 20);
        TAggregateRoot FirstOrDefault(Expression<Func<TAggregateRoot, bool>> predicate);
        bool Contains(Expression<Func<TAggregateRoot, bool>> predicate);
        TAggregateRoot Find(params object[] keys);
        int Count { get; }
        int CountWithCondition(Expression<Func<TAggregateRoot, bool>> predicate);
        /// <summary>
        /// Get the object by execute the raw sql statements.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        IQueryable<TAggregateRoot> GetWithRawSql(string query, params object[] parameters);
    }
}
